﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FrameWorkWeb;
using System.Data.SqlClient;
using System.Data;

namespace FrameWork.web.Middle.OperateCS
{
    public class ColConfigCS
    {

        public int ColConfig_Create(enColConfig _enColConfig)
        {
            SqlParameter[] sp = new SqlParameter[3]{
				new SqlParameter("@ConfigName",SqlDbType.VarChar,50),
				new SqlParameter("@IsDefault",SqlDbType.Int),
				new SqlParameter("@Remark",SqlDbType.VarChar,500),
			
			};
            //
            if (_enColConfig.ConfigName != "")
            {
                sp[0].Value = _enColConfig.ConfigName;
            }
            else
            {
                sp[0].Value = DBNull.Value;
            }

            sp[0].Direction = ParameterDirection.Input;


            //
            if (_enColConfig.IsDefault != int.MinValue)
            {
                sp[1].Value = _enColConfig.IsDefault;
            }
            else
            {
                sp[1].Value = DBNull.Value;
            }

            sp[1].Direction = ParameterDirection.Input;


            //
            if (_enColConfig.Remark != "")
            {
                sp[2].Value = _enColConfig.Remark;
            }
            else
            {
                sp[2].Value = DBNull.Value;
            }

            sp[2].Direction = ParameterDirection.Input;


            try
            {
                DataSet ds= SqlHelper.ExecuteDataset(CommandType.StoredProcedure, "dbo.wColConfig_Create", sp);
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    return int.Parse(ds.Tables[0].Rows[0][0].ToString());
                }
                else
                { return -1; }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        public int ColConfig_Delete(enColConfig _enColConfig)
        {
            SqlParameter[] sp = new SqlParameter[1]{
				new SqlParameter("@ID",SqlDbType.Int),
			
			};
            //
            if (_enColConfig.ID != int.MinValue)
            {
                sp[0].Value = _enColConfig.ID;
            }
            else
            {
                sp[0].Value = DBNull.Value;
            }

            sp[0].Direction = ParameterDirection.Input;


            try
            {
                int i = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "dbo.wColConfig_DeleteByID", sp);
                return i;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        public int ColConfig_Update(enColConfig _enColConfig)
        {
            SqlParameter[] sp = new SqlParameter[4]{
				new SqlParameter("@ID",SqlDbType.Int),
				new SqlParameter("@ConfigName",SqlDbType.VarChar,50),
				new SqlParameter("@IsDefault",SqlDbType.Int),
				new SqlParameter("@Remark",SqlDbType.VarChar,500),
			
			};
            //
            if (_enColConfig.ID != int.MinValue)
            {
                sp[0].Value = _enColConfig.ID;
            }
            else
            {
                sp[0].Value = DBNull.Value;
            }

            sp[0].Direction = ParameterDirection.Input;


            //
            if (_enColConfig.ConfigName != "")
            {
                sp[1].Value = _enColConfig.ConfigName;
            }
            else
            {
                sp[1].Value = DBNull.Value;
            }

            sp[1].Direction = ParameterDirection.Input;


            //
            if (_enColConfig.IsDefault != int.MinValue)
            {
                sp[2].Value = _enColConfig.IsDefault;
            }
            else
            {
                sp[2].Value = DBNull.Value;
            }

            sp[2].Direction = ParameterDirection.Input;


            //
            if (_enColConfig.Remark != "")
            {
                sp[3].Value = _enColConfig.Remark;
            }
            else
            {
                sp[3].Value = DBNull.Value;
            }

            sp[3].Direction = ParameterDirection.Input;


            try
            {
                int i = SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "dbo.wColConfig_Update", sp);
                return i;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
